"""
Case Type   : 功能测试
Case Name   : gs_ddr工具适配池化双集群显示功能测试
Create At   : 2025/03/25
Owner       : @chen
Description :
    1.gs_ddr -?
    2.gs_ddr --help
    3.gs_ddr -V
    4.gs_ddr --version
    5.gs_ddr -？
    gs_ddr --?
    6.gs_ddr --V
    gs_ddr -v
    7.gs_ddr -version
Expect      :
    1.显示正常
    2.显示正常
    3.显示正常
    4.显示正常
    5.合理报错
    6.合理报错
    7.合理报错
History     :
"""

import unittest
import os
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro
logger = Logger()

class Dual_Cluster_Redution_Case0001(unittest.TestCase):
    def setUp(self):
        logger.info(f'--------{os.path.basename(__file__)} start--------')
        self.pri_node = Node('P_PrimaryDbUser')

    def test_shared_storage(self):
        opt_help = ['-?', '--help']
        for cmd in opt_help:
            logger.info(f'-----gs_ddr {cmd} expect:显示正常-----')
            check_cmd = f'source {macro.DB_ENV_PATH}; gs_ddr {cmd}'
            logger.info(check_cmd)
            res = self.pri_node.sh(check_cmd).result()
            self.assertTrue('Usage' in res and 'Options' in res, 
                f'{check_cmd} 命令校验失败')
        opt_version = ['-V', '--version']
        for cmd in opt_version:
            logger.info(f'-----gs_ddr {cmd} expect:显示正常-----')
            check_cmd = f'source {macro.DB_ENV_PATH}; gs_ddr {cmd}'
            logger.info(check_cmd)
            res = self.pri_node.sh(check_cmd).result()
            self.assertTrue('gs_ddr' in res and 'openGauss OM' in res, 
                f'{check_cmd} 命令校验失败')

        opt_err = ['-？', '--?', '--V', '-v', '-version']
        for cmd in opt_err:
            logger.info(f'-----gs_ddr {cmd} expect:合理报错-----')
            check_cmd = f'source {macro.DB_ENV_PATH}; gs_ddr {cmd}'
            logger.info(check_cmd)
            res = self.pri_node.sh(check_cmd).result()
            self.assertIn(f'gs_ddr: error: no such option: {cmd}', res, 
                f'{check_cmd} 命令校验失败')

    def tearDown(self):
        logger.info(f'-----{os.path.basename(__file__)} end-----')
